package reloj;

import java.util.*;
import java.text.DateFormat;

public class RelojThreadDemo extends Thread {
    private static javax.swing.JLabel lblreloj;
   
    public RelojThreadDemo() {
        lblreloj = new javax.swing.JLabel();
        lblreloj.setFont(new java.awt.Font("Dialog", 0, 24));
        lblreloj.setForeground(new java.awt.Color(160, 0, 0));
        lblreloj.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    }

    public void run() {
        Calendar cal;
        Date date;
        DateFormat dfmt;        
        while (true) {
            cal = Calendar.getInstance();
            date = cal.getTime();
            dfmt = DateFormat.getTimeInstance();
            lblreloj.setText(dfmt.format(date));
            try {
                 sleep(1000);
            } catch (InterruptedException e) { }
        }
    }  
    
    public static void main(String args[]) {
        new RelojThreadDemo().start();
        javax.swing.JOptionPane.showMessageDialog(null,
                    lblreloj,
                    "ThreadReloj",
                    javax.swing.JOptionPane.PLAIN_MESSAGE);
        System.exit(0);
    }    
}

